using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Assets.Actions.Base;
using System.Globalization;

namespace VSSDKAssist.Recipes.CreateVSCommand
{
	/// <summary>
	/// Action that creates the GroupDefinition section on the ctc file
	/// </summary>
	public class CreateGroupDefinitionAction : ActionBase
	{
		#region Properties
		private string commandName;

		/// <summary>
		/// Gets or sets the name of the command.
		/// </summary>
		/// <value>The name of the command.</value>
		[Input(Required = true)]
		public string CommandName
		{
			get { return commandName; }
			set { commandName = value; }
		}

		private string groupName;

		/// <summary>
		/// Gets or sets the name of the group.
		/// </summary>
		/// <value>The name of the group.</value>
		[Input(Required = true)]
		public string GroupName
		{
			get { return groupName; }
			set { groupName = value; }
		}

		private string parentGroupGuidAlias;

		/// <summary>
		/// Gets or sets the parent group GUID alias.
		/// </summary>
		/// <value>The parent group GUID alias.</value>
		[Input(Required = true)]
		public string ParentGroupGuidAlias
		{
			get { return parentGroupGuidAlias; }
			set { parentGroupGuidAlias = value; }
		}

		private string parentGroupIdAlias;

		/// <summary>
		/// Gets or sets the parent group id alias.
		/// </summary>
		/// <value>The parent group id alias.</value>
		[Input(Required = false)]
		public string ParentGroupIdAlias
		{
			get { return parentGroupIdAlias; }
			set { parentGroupIdAlias = value; }
		}

		private bool defaultParentGroup;

		/// <summary>
		/// Gets or sets a value indicating whether [default parent group].
		/// </summary>
		/// <value><c>true</c> if [default parent group]; otherwise, <c>false</c>.</value>
		[Input(Required = true)]
		public bool DefaultParentGroup
		{
			get { return defaultParentGroup; }
			set { defaultParentGroup = value; }
		}

		private string otherParentGroupGuidAlias;

		/// <summary>
		/// Gets or sets the other parent group GUID alias.
		/// </summary>
		/// <value>The other parent group GUID alias.</value>
		[Input(Required = false)]
		public string OtherParentGroupGuidAlias
		{
			get { return otherParentGroupGuidAlias; }
			set { otherParentGroupGuidAlias = value; }
		}

		private string otherParentGroupIdAlias;

		/// <summary>
		/// Gets or sets the other parent group id alias.
		/// </summary>
		/// <value>The other parent group id alias.</value>
		[Input(Required = false)]
		public string OtherParentGroupIdAlias
		{
			get { return otherParentGroupIdAlias; }
			set { otherParentGroupIdAlias = value; }
		}

		private string groupDefinition;

		/// <summary>
		/// Gets or sets the group definition.
		/// </summary>
		/// <value>The group definition.</value>
		[Output]
		public string GroupDefinition
		{
			get { return groupDefinition; }
			set { groupDefinition = value; }
		}
		#endregion

		/// <summary>
		/// Called when [execute].
		/// </summary>
		protected override void OnExecute()
		{
			// NewGroup                          Parent Group                       Priority
			// guidVsPackage1CmdSet:MyMenuGroup, guidSHLMainMenu:IDM_VS_MENU_TOOLS, 0x0100;

			if(this.DefaultParentGroup)
			{
				groupDefinition =
					string.Format(
						CultureInfo.CurrentCulture,
						"    guid{0}:grpid{1}, {2}:{3}, 0x0100;",
						this.commandName,
						this.groupName,
						this.parentGroupGuidAlias,
						this.ParentGroupIdAlias);
			}
			else
			{
				groupDefinition =
					string.Format(
						CultureInfo.CurrentCulture,
						"    guid{0}:grpid{1}, {2}:{3}, 0x0100;",
						this.commandName,
						this.groupName,
						this.OtherParentGroupGuidAlias,
						this.OtherParentGroupIdAlias);
			}
		}
	}
}